package com.mooc.yohoshop.ui.car;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.mooc.yohoshop.R;
import com.mooc.yohoshop.entity.CarEntity;

import org.jetbrains.annotations.NotNull;

public class CarAdapter extends BaseQuickAdapter<CarEntity.Values, BaseViewHolder> {

    private RecyclerView.RecycledViewPool pool;

    public CarAdapter() {
        super(R.layout.item_car);
        addChildClickViewIds(R.id.car_sel_img);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, CarEntity.Values values) {
        RecyclerView recyclerView = baseViewHolder.getView(R.id.car_goods_rv);
        baseViewHolder.setImageResource(R.id.car_sel_img,R.drawable.checkbox_payment_normal);
        if (values.selFlag){
            baseViewHolder.setImageResource(R.id.car_sel_img,R.drawable.checkbox_payment_select);
        }
        baseViewHolder.setText(R.id.carlist_item_title,"店铺:"+values.car_goods);
        if (pool == null)
            pool =recyclerView.getRecycledViewPool();
        CarGoodsAdapter adapter = (CarGoodsAdapter) recyclerView.getAdapter();
        if (adapter == null){
            adapter = new CarGoodsAdapter();
            LinearLayoutManager manager = new LinearLayoutManager(baseViewHolder.itemView.getContext());
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(manager);
            recyclerView.setAdapter(adapter);
        }
        adapter.setNewInstance(values.car_goods);
    }
}
